package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.management.RuntimeErrorException;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.User;
import entity.UserType;

/**
 * Session Bean implementation class EaoUser
 */
@Stateless(mappedName = "eaoUserType")
@LocalBean
public class EaoUserType {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoUserType() {
        // TODO Auto-generated constructor stub
    }

    public UserType find(int id) {
        return em.find(UserType.class, id);
    }

    public List<UserType> list() {
    	return em.createQuery("SELECT ut FROM UserType ut", UserType.class).getResultList();
    }

    public void create(UserType UserType) throws Exception {
        try{
        	em.persist(UserType);
        	em.flush();
        }catch (Exception e) {
        	throw new Exception(e.getMessage());
		}
    }

    public void update(UserType UserType) {
        em.merge(UserType);
    }

    public void delete(UserType UserType) {
        em.remove(em.contains(UserType) ? UserType : em.merge(UserType));
    }

}
